/-app
/-docs
/-files
/-imports
/-persistence
/-typescript ...
CodeMirrorScriptSnapshot.ts
TypeScriptService.ts
/-typings
codemirror.addons.d.ts
codemirror.d.ts
knockout.d.ts
typescriptServices.d.ts
websql.d.ts
zip.d.ts
errors.js
functions.ts
index.html
try.js
x
1
module teapo.typescript {
2
​
3
  export class TypeScriptService {
4
​
5
    service: ts.LanguageService;
6
​
7
    compilerOptions: ts.CompilerOptions;
8
    cancellation: ts.CancellationToken = null;
9
    currentDirectory = '/';
10
    defaultLibFilename = '#lib.d.ts';
11
​
12
    log: (text: string) => void = null;
13
​
14
    private _scriptFileNames: string[] = null;
15
    private _scripts: { [file: string]: TypeScript.IScriptSnapshot; } = {};
16
​
17
    constructor() {
18
      var factory = ts.createLanguageService(
19
        this._createHost(),
20
        this._createRegistry());
21
    }
22
​
23
    addFile(file: string, doc: CodeMirror.Doc);
24
    addFile(file: string, text: string);
25
    addFile(file: string, content: any){
26
    }
27
​
28
    removeFile(file: string) {
29
    }
30
​
31
    private _createRegistry() {
32
      return ts.createDocumentRegistry();
33
    }
34
  
35
    private _createHost(): ts.LanguageServiceHost {
36
      return {
37
        getCompilationSettings: () => this.compilerOptions,
38
        getScriptFileNames: () => {
39
          if (!this._scriptFileNames) {
40
            this._scriptFileNames = objectKeys(this._scripts);
41
            this._scriptFileNames.sort();
42
          }
43
          return this._scriptFileNames;
44
        },
45
        getScriptVersion: (file) => {
46
          var script = <CodeMirrorScriptSnapshot>this._scripts[file];
47
          return script.version ? script.version + '' : '0';
48
        },
49
        getScriptIsOpen: () => true,
50
        getScriptSnapshot: (file) => this._scripts[file],
51
        getLocalizedDiagnosticMessages: () => null,
52
        getCancellationToken: () => this.cancellation,
53
        getCurrentDirectory: () => this.currentDirectory,
54
        getDefaultLibFilename: () => this.defaultLibFilename,
55
        log: (text) => {
56
          if (this.log) {
57
            this.log(text);
58
          }
59
          else {
60
                      if (typeof console !== 'undefined')
61
                          console.log(text);
62
          }
63
        }
64
      };
65
      
66
    }
67
    
68
  }
69
​
70
}
46:55